package com.ltf.cs;

import com.ltf.entity.Mark;
import com.ltf.entity.Task;
import com.ltf.entity.XJson;
import com.ltf.entity.XUser;
import com.ltf.service.MarkService;
import com.ltf.service.TaskService;
import com.ltf.service.XUserService;
import com.ltf.utils.PackJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/fore/stu")
public class MyStuController {
    @Autowired
    XUserService userService;
    @Autowired
    TaskService taskService;
    @Autowired
    MarkService markService;

    public MyStuController() {
    }

    @GetMapping("/findMyCourse")
    public XJson findMyCourse() {//查询我的
        Object phone = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        XUser newUser = this.userService.findByPhone((String) phone);
        if (newUser == null) {
            return PackJson.packX(404, "用户未发现", (Object) null);
        } else {
            List<Task> tasks = this.taskService.findByClzno(newUser.getClz().getClzno());
            System.out.println(tasks);
            return PackJson.packX(200, "", tasks);
        }
    }

    @GetMapping("/findMyMark")
    public XJson findMyMark() {//查询我的成绩
        Object phone = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        XUser newUser = this.userService.findByPhone((String) phone);
        if (newUser == null) {
            return PackJson.packX(404, "用户未发现", (Object) null);
        } else {
            List<Mark> marks = this.markService.findBySno(newUser.getPhone());
            System.out.println(marks);
            return PackJson.packX(200, "", marks);
        }
    }
    //加入学生给教师评分功能,生成出来后并告诉我怎么用apipost测通,然


}
